<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <base href="<%=basePath%>">
    
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="css/index.css" />
	
	<title>index Page</title>

</head>
<body onload="init();">
	<div style="margin:0;padding:5px 50px 0px 50px;color:#333;">
		<fieldset>
			<legend>修改公告</legend>
			<div align="right" style="padding:5px 0 0 50px;">
				<a href="#" class="easyui-linkbutton" style="height:24px;" onclick="javascript :history.back(-1)">返回</a>
			</div>
			<form  enctype="multipart/form-data" id="notice_modify" name="notice_modify" action="noticeAction!addNotice" style="margin:0;padding:5px 0 0 0px;color:#333;">
				<p>公告标题：<input class="textbox" name="noticeTitle" id="noticeTitle" value="${noticePo.noticeTitle }" style="width:200px;"></p>
				<p>有效期限：<input class="easyui-datetimebox" name="noticeOverdueTime" id="noticeOverdueTime" data-options="required:true,editable:false" value="${noticePo.noticeOverdueTime }" style="width:200px"></p>
				<p>公告内容：<script name="noticeContent" id="noticeContent" type="text/plain">${noticePo.noticeContent}</script></p>
				<input type="hidden" name="noticeId" id="noticeId" value="${noticePo.noticeId }">
				<input type="hidden" name="noticeAddUser" id="noticeAddUser" value="${noticePo.noticeAddUser }">
				<input type="hidden" class="easyui-datetimebox" name="noticeAddTime" id="noticeAddTime" value="${noticePo.noticeAddTime }">
				<input type="hidden" name="showState" id="showState" value="${noticePo.showState }">
				</br>
				<p style="padding:5px 0 0 400px;">
					<a href="#" class="easyui-linkbutton" style="height:24px;" onclick="fileUpload();">发布</a>
					<a href="#" class="easyui-linkbutton" style="height:24px;" onclick="reset();">取消</a>
				</p>
		
			</form>
		</fieldset>
	</div>
	<script type="text/javascript" src="<%=path%>/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="<%=path%>/easyui/ajaxfileupload.js"></script>
	<script type="text/javascript" src="<%=path%>/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=path%>/easyui/locale/easyui-lang-zh_CN.js" ></script>
	<script type="text/javascript" src="<%=path%>/jsp/notice/ueditor1_3_6/ueditor.config.js"></script>
	<script type="text/javascript" src="<%=path%>/jsp/notice/ueditor1_3_6/ueditor.all.min.js"> </script>
	<script type="text/javascript" src="<%=path%>/jsp/notice/ueditor1_3_6/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript">
		function reset(){
			$('#notice_modify')[0].reset(); 
		}
		
		function fileUpload() {
			if ($('#notice_modify').form('validate')) {
				var formData = new FormData($( "#notice_modify" )[0]);  
				$.ajax({
					url : 'noticeAction!saveOrUpdateNotice?modify=1',
					type : 'post',
					data : formData,
					dataType:"json",
					cache: false,  
		            processData: false,  
		            contentType: false,
					beforeSend : function () {
						$.messager.progress({
							text : '正在提交中...'
						});
					},
					success : function (data, response, status) {
						$.messager.progress('close');
						if(data){
							$.messager.show({
								title : '提示',
								msg : '成功提交公告'
							});
							setInterval("xx(" + data + ")",1500);  
						}else {
							$.messager.alert('公告提交失败！', '未知错误导致失败，请重试！', 'warning');
						}
					}
				});
			}
		}
		function xx(data){
			window.location.href = "noticeAction!getNoticeByNoticeId?noticeId=" + data + "&look=one";
		}
		function init(){
			var config = {
			        initialFrameWidth:'100%',  
			        initialFrameHeight:250,   
			        autoHeightEnabled:false, 
			};
			UE.getEditor('noticeContent',config);
		}
		$.extend($.fn.datetimebox.defaults.editors, {
			datetimebox : {
				init: function(container, options){
					var input = $('<input type="text">').appendTo(container);
					options.editable = false;
					input.datetimebox(options);
					return input;
				},
				getValue: function(target){
					return $(target).datetimebox('getValue');
				},
				setValue: function(target, value){
					$(target).datetimebox('setValue', value);
				},
				resize: function(target, width){
					$(target).datetimebox('resize', width);
				},
				destroy : function (target) {
					$(target).datetimebox('destroy');
				}
			}
		});

		$(function () {
			
			$('input[name="noticeTitle"]').validatebox({
				required : true,
				missingMessage : '请输入公告标题',
			});
			tool = {
					send : function(){
						if ($('#notice_modify').form('validate')) {
							var formData = new FormData($( "#notice_modify" )[0]);  
							$.ajax({
								url : 'noticeAction!addNotice',
								type : 'post',
								data : formData,
								dataType:"json",
								cache: false,  
					            processData: false,  
					            contentType: false,
								beforeSend : function () {
									$.messager.progress({
										text : '正在发布中...'
									});
								},
								success : function (data, response, status) {
									$.messager.progress('close');
									
									if (data > 0) {
										$.messager.alert('提示', '成功修改公告！', 'warning');
										$('#notice_modify')[0].reset();  
									} else {
										$.messager.alert('公告发布失败！', '未知错误导致失败，请重试！', 'warning');
									}
								}
							});
						}
					}
				};
		});
	</script>
</body>
</html>